<template>
  <div class="box-body form-horizontal">
    <div class="form-group">
      <label class="col-sm-2 control-label">所属部门</label>
      <div class="col-sm-4">
        <Depart ref='depart' :selectedDepart='queryData.depart' @departchanged="val => this.queryData.depart = val"></Depart>
      </div>
      <label for="inputUserName" class="col-sm-2 control-label">姓名</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="inputUserName" v-model="queryData.name" placeholder="姓名">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">证件</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="queryCert" v-model="queryData.idCard" placeholder="身份证">
      </div>
      <label class="col-sm-2 control-label">民族</label>
      <div class="col-sm-4">
        <National :withUnlimit='true' :selectedNational="queryData.national" @nationnalchange="val => this.queryData.national = val"></National>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">移动电话</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="phone" v-model="queryData.phone" placeholder="移动电话">
      </div>
      <label class="col-sm-2 control-label">办公电话</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="tel" v-model="queryData.tel" placeholder="办公电话">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">出生年月</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.birtFrom' @timeChanged="time => this.queryData.birtFrom = time" ref="birthFrom"></MyDatePicker>
      </div>
      <label class="col-sm-2 control-label">到</label>
      <div class="col-sm-4">
        <MyDatePicker ref="birthTo" v-bind:date='queryData.birtTo' @timeChanged="time => this.queryData.birtTo = time"></MyDatePicker>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">籍贯</label>
      <div class="col-sm-4">
        <Birthplace :withUnlimit='true' v-bind:birthplace="queryData.birthplace"></Birthplace>
      </div>
      <label class="col-sm-2 control-label">性别</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.sex">
            <option :key="option.id" v-for="option in this.sexes" v-bind:value="option.id">{{ option.name }}</option>
          </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">用工性质</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.workType">
            <option :key="option.id" v-for="option in this.workTypes" v-bind:value="option.id">{{ option.name }}</option>
          </select>
      </div>
      <label class="col-md-2 control-label my-label">在职状态</label>
      <div class="col-md-4">
        <select class="form-control" v-model="queryData.empState">
            <option :key="option.id" v-for="option in this.states" v-bind:value="option.id">{{ option.name }}</option>
          </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">入职时间</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.entryFrom' @timeChanged="time => this.queryData.entryFrom = time" ref="entryFrom"></MyDatePicker>
      </div>
      <label class="col-sm-2 control-label">到</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.entryTo' @timeChanged="time => this.queryData.entryTo = time" ref="entryTo"></MyDatePicker>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">岗位类型</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.postType">
            <option :key="option.id" v-for="option in this.postTypes" v-bind:value="option.id">{{ option.name }}</option>
          </select>
      </div>
      <label class="col-md-2 control-label my-label">来源渠道</label>
      <div class="col-sm-4">
        <Channel ref='channel' :withUnlimit='true' :selectedChannel='queryData.channel' @channelchanged="val => queryData.channel = val"></Channel>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">政治面貌</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.politicalStatus">
          <option :key="option.id" v-for="option in this.politicalStatuses" v-bind:value="option.id">{{ option.name }}</option>
        </select>
      </div>
      <label class="col-sm-2 control-label">职务级别</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.positionType">
          <option :key="option.id" v-for="option in this.positionTypes" v-bind:value="option.id">{{ option.name }}</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">全日制教育学位</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="FtSchool" v-model="queryData.FtSchool" placeholder="全日制教育学位">
      </div>
      <label class="col-sm-2 control-label">婚姻状况</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.married">
          <option :key="option.id" v-for="option in this.marries" v-bind:value="option.id">{{ option.name }}</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">职称层级</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.ptl">
          <option :key="option.id" v-for="option in this.ptls" v-bind:value="option.id">{{ option.name }}</option>
        </select>
      </div>
      <label class="col-sm-2 control-label">职称名称</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="txtPtn" v-model="queryData.ptj" placeholder="职称名称">
      </div>
    </div>
  </div>
</template>

<script>
  import Multiselect from 'vue-multiselect'
  import MyDatePicker from '../../mycomponents/common/MyDatePicker'
  import Depart from '../../mycomponents/common/Depart'
  import National from '../../mycomponents/common/National'
  import Channel from '../../mycomponents/common/Channel'
  import Birthplace from '../../mycomponents/common/Birthplace'
  import WorkType from '../../mycomponents/common/WorkType'
  import EmployeeStatus from '../../mycomponents/common/EmployeeStatus'
  import Policy from '../../mycomponents/common/Policy'
  export default {
    "name": "userQuery",
    components: {
      Depart,
      Multiselect,
      MyDatePicker,
      National,
      Birthplace,
      Channel,
      WorkType,
      EmployeeStatus,
      Policy
    },
    props: ['data'],
    data: function() {
      return {
        queryData: {
          phone: '',
          tel: '',
          FtSchool:'',
          depart: null,
          name: null,
          idCard: null,
          national: -1,
          birtFrom: '',
          birtTo: '',
          entryFrom: '',
          entryTo: '',
          birthplace: {
            province: -1,
            city: -1
          },
          sex: -1,
          married:-1,
          workage: -1,
          postType: -1,
          empState: -1,
          positionlevel: -1,
          discipline: null,
          degree: -1,
          workType: -1,
          channel: -1,
          politicalStatus:-1,
          positionType:-1,
          ptl:-1,
          positions: null,
          ptj:''
        },
        politicalStatuses:[{
          id: -1,
          name: "不限"
        }],
        sexes: [{
          id: -1,
          name: "不限"
        }],
        postTypes: [{
          id: -1,
          name: '不限'
        }],
        positionlevels: [{
          id: -1,
          name: '不限'
        }],
        degrees: [{
          id: -1,
          name: '不限'
        }],
        positions: [{
          id: -1,
          name: '不限'
        }],
        workTypes: [{
          id: -1,
          name: '不限'
        }],
        states: [{
          id: -1,
          name: '不限'
        }],
        channels: [{
          id: -1,
          name: '不限'
        }],
        positionTypes:[{
          id: -1,
          name: '不限'
        }],
        ptls:[{
          id: -1,
          name: '不限'
        }],
        marries:[{
          id: -1,
          name: '不限'
        }]
      }
    },
    created: function() {
      this.marries = this.marries.concat(this.$store.state.sysconfigs.married)
      this.workTypes = this.workTypes.concat(this.$store.state.sysconfigs.workerType)
      this.postTypes = this.postTypes.concat(this.$store.state.sysconfigs.postTypes)
      this.degrees = this.degrees.concat(this.$store.state.sysconfigs.FtEducation)
      this.sexes = this.sexes.concat(this.$store.state.sysconfigs.sex)
      this.positions = this.positions.concat(this.$store.state.sysconfigs.positions)
      this.states = this.states.concat(this.$store.state.sysconfigs.state)
      this.channels = this.channels.concat(this.$store.state.sysconfigs.channels)
      this.politicalStatuses = this.politicalStatuses.concat(this.$store.state.sysconfigs.politicalStatus)
      this.positionTypes = this.positionTypes.concat(this.$store.state.sysconfigs.positionType)
      this.ptls = this.ptls.concat(this.$store.state.sysconfigs.ptl)
      this.positionlevels = this.ptls.concat(this.$store.state.sysconfigs.positionlevels)
    },
    methods: {
      getData() {
        var newQueryData = []
        // 单位
        if (this.queryData.depart != null && this.queryData.depart.length > 0) {
          newQueryData.push({
            field: "departmentId",
            op: "=",
            value: this.queryData.depart[this.queryData.depart.length - 1]
          })
        }
        // 名称
        if (this.queryData.name) {
          newQueryData.push({
            field: "name",
            op: "like",
            value: '%' + this.queryData.name + '%'
          })
        }
        // 证明
        if (this.queryData.idCard) {
          newQueryData.push({
            field: "idcard",
            op: "like",
            value: '%' + this.queryData.idCard + '%'
          })
        }
        // 民族
        if (this.queryData.national != -1) {
          newQueryData.push({
            field: "nation",
            op: "=",
            value: this.queryData.national
          })
        }
        // 生日
        if (this.queryData.birtFrom) {
          newQueryData.push({
            field: "birthday",
            op: ">=",
            value: this.queryData.birtFrom
          })
        }
        // 生日
        if (this.queryData.birtTo) {
          newQueryData.push({
            field: "birthday",
            op: "<",
            value: this.queryData.birtTo
          })
        }
        // 入职时间
        if (this.queryData.entryFrom) {
          newQueryData.push({
            field: "createTime",
            op: ">=",
            value: this.queryData.entryFrom
          })
        }
        // 入职时间
        if (this.queryData.entryTo) {
          newQueryData.push({
            field: "createTime",
            op: "<",
            value: this.queryData.entryTo
          })
        }
        // 籍贯
        if (this.queryData.birthplace.province != -1 || this.queryData.birthplace.city != -1) {
          var value = null
          if (this.queryData.birthplace.province != -1) {
            value = this.queryData.birthplace.province + '%'
          }
          if (this.queryData.birthplace.city != -1) {
            if (value != null) {
              value = value + this.queryData.birthplace.city
            } else {
              value = '%' + this.queryData.birthplace.city + '%'
            }
          }
          newQueryData.push({
            field: "nativePlace",
            op: "like",
            value: value
          })
        }
        // 婚姻状况
        if (this.queryData.married != -1) {
          newQueryData.push({
            field: "married",
            op: "=",
            value: this.queryData.married
          })
        }
        // 职称层级
        if (this.queryData.ptl != -1) {
          newQueryData.push({
            field: "ptl",
            op: "=",
            value: this.queryData.ptl
          })
        }
        // 性别
        if (this.queryData.sex != -1) {
          newQueryData.push({
            field: "sex",
            op: "=",
            value: this.queryData.sex
          })
        }
        // 工作类型
        if (this.queryData.workType != -1) {
          newQueryData.push({
            field: "workerType",
            op: "=",
            value: this.queryData.workType
          })
        }
        // 政治面貌
        if (this.queryData.politicalStatus != -1) {
          newQueryData.push({
            field: "politicalStatus",
            op: "=",
            value: this.queryData.politicalStatus
          })
        }
        // 在职状态
        if (this.queryData.empState != -1) {
          newQueryData.push({
            field: "state",
            op: "=",
            value: this.queryData.empState
          })
        }
        // 来源
        if (this.queryData.channel != -1) {
          newQueryData.push({
            field: "source",
            op: "=",
            value: this.queryData.channel
          })
        }
        // 移动电话
        if (this.queryData.phone != '') {
          newQueryData.push({
            field: "phone",
            op: "like",
            value: '%' + this.queryData.phone + '%'
          })
        }
        // 办公电话
        if (this.queryData.tel != '') {
          newQueryData.push({
            field: "tel",
            op: "like",
            value: '%' + this.queryData.tel + '%'
          })
        }
        // 岗位
        if (this.queryData.postType != -1) {
          newQueryData.push({
            field: "gwType",
            op: "=",
            value: this.queryData.postType
          })
        }
        // 全日制教育学校
        if (this.queryData.FtSchool){
          newQueryData.push({
            field: "FtSchool",
            op: "like",
            value: '%' + this.queryData.FtSchool + '%'
          })
        }
        if (this.queryData.positionType != -1){
          newQueryData.push({
            field: "positionType",
            op: "=",
            value: this.queryData.positionType
          })
        }
        // 职称名称
        if( this.queryData.ptj){
          newQueryData.push({
            field: "ptj",
            op: "like",
            value: '%' + this.queryData.ptj + '%'
          })
        }
        // 职务
        if (this.queryData.positions != null && this.queryData.positions.length > 0) {
          var positions = null
          for (var pos in this.queryData.positions) {
            if (!positions) {
              positions = this.queryData.positions[pos].name
            } else
              positions = positions + ',' + this.queryData.positions[pos].name
          }
          newQueryData.push({
            field: "positions",
            op: "=",
            value: positions
          })
        }
        return newQueryData
      }
    }
  }
</script>

